// src/router/index.ts
import { title } from 'process';
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';

export const Layout = () => import('../layout/index.vue');

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/role",
    meta:{
      title:"系统管理"
    },
    children: [
      {
        path: "role",
        component: () => import("@/views/role/index.vue"),
        name: "role",
        meta: {
          title: "角色管理",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "user",
        component: () => import("@/views/user/index.vue"),
        name: "user",
        meta: {
          title: "用户管理",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "menu",
        component: () => import("@/views/menu/index.vue"),
        name: "menu",
        meta: {
          title: "菜单管理",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "dict",
        component: () => import("@/views/dict/index.vue"),
        name: "dict",
        meta: {
          title: "字典管理",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      // {
      //   path: "401",
      //   component: () => import("@/views/error-page/401.vue"),
      //   meta: { hidden: true },
      // },
      // {
      //   path: "404",
      //   component: () => import("@/views/error-page/404.vue"),
      //   meta: { hidden: true },
      // },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 })
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: '/login' });
  location.reload();
}

export default router;
